import "reflect-metadata"
import path from "path";

// 配置环境变量
import dotenv from "dotenv";
dotenv.config();
import express from "express";

// 捕获异步错误
import "express-async-errors";

// 初始化数据库
import "./db/index";

import session from "express-session";
import { routerSetup } from "./modules/routerSetup";

const setup = async () => {
  // 创建路由
  const app = express();
  app.use(express.json());
  app.use("/", express.static(path.join(__dirname, "../public")));
  app.use(
    session({
      secret: "ligy21240871",
      saveUninitialized: false,
      resave: true,
    })
  );

  // 自动导入路由
  await routerSetup(app)

  // 启动服务
  app.listen(process.env.Y_APP_PORT, () => {
    console.log(`监听${process.env.Y_APP_PORT}端口中...`);
  });
}
setup()